/**
 * 
 */
package com.huarui.desktop.model;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * @author sunpeng
 * 
 */
public class Module {

	/**
	 * 模块ID号,全局唯一,必须设置
	 */
	private String id;
	/**
	 * 模块类型,比如:系统/配置,目前暂时没有使用,可以不设置
	 */
	private String type;
	/**
	 * 定义模块的脚本文件相对路径,比如:/order/order.js,可以不设置
	 * 当不配置scriptUrl时,JS将自动生成scriptUrl地址,生成地址规则为:/module的ID/module的ID.js
	 */
	private String scriptUrl;

	/**
	 * 模块的特殊样式文件相对路径,比如:/order/resources/styles.css,可以不设置
	 */
	private String stylesheetUrl;

	/**
	 * 模块初始化参数,调用模块的init方法时传入,可以不设置
	 */
	private Map<String, String> initParams;
	/**
	 * 模块的Javascript类名，必须设置
	 */
	private String className;
	/**
	 * 模块的启动配置信息，可以不设置
	 */
	private ModuleLauncher launcher;
	/**
	 * 模块在开始菜单的加载位置，可以不设置，不设置时不会在开始菜单加载
	 */
	private Map<ModuleLauncherAnchor, String> launcherPaths;
	/**
	 * 模块是否自动运行
	 */
	private boolean autorun;
	/**
	 * 模块是否放入快速启动任务栏
	 */
	private boolean inQuickstart;
	/**
	 * 模块是否放入桌面的快捷方式
	 */
	private boolean inShortcut;

	/**
	 * 模块启动后是否放入任务条
	 */
	private boolean markTask=true;
	
	private static final String[] excludeProperties = { "stylesheetUrl",
			"autorun", "inQuickstart", "inShortcut" };
	private static JsonConfig jsonConfig;
	static {
		jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(excludeProperties);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Map<String, String> getInitParams() {
		return initParams;
	}

	public void setInitParams(Map<String, String> initParams) {
		this.initParams = initParams;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public ModuleLauncher getLauncher() {
		return launcher;
	}

	public void setLauncher(ModuleLauncher launcher) {
		this.launcher = launcher;
	}

	public Map<ModuleLauncherAnchor, String> getLauncherPaths() {
		return launcherPaths;
	}

	public void setLauncherPaths(Map<ModuleLauncherAnchor, String> launcherPaths) {
		this.launcherPaths = launcherPaths;
	}

	public boolean isAutorun() {
		return autorun;
	}

	public void setAutorun(boolean autorun) {
		this.autorun = autorun;
	}

	public boolean isInQuickstart() {
		return inQuickstart;
	}

	public void setInQuickstart(boolean inQuickstart) {
		this.inQuickstart = inQuickstart;
	}

	public boolean isInShortcut() {
		return inShortcut;
	}

	public void setInShortcut(boolean inShortcut) {
		this.inShortcut = inShortcut;
	}

	public String getScriptUrl() {
		return scriptUrl;
	}

	public void setScriptUrl(String scriptUrl) {
		this.scriptUrl = scriptUrl;
	}

	public String getStylesheetUrl() {
		return stylesheetUrl;
	}

	public void setStylesheetUrl(String stylesheetUrl) {
		this.stylesheetUrl = stylesheetUrl;
	}

	public String toString() {
		Object jsonObject = JSONObject.fromObject(this, jsonConfig);
		return jsonObject.toString();
	}

	public boolean isMarkTask() {
		return markTask;
	}

	public void setMarkTask(boolean markTask) {
		this.markTask = markTask;
	}

	public boolean equals(Object object) {
		if (this == object) {
			return true;
		}
		if (object instanceof Module) {
			Module module = (Module) object;
			return StringUtils.equals(this.getId(), module.getId());
		}
		return false;
	}

	public int hashCode() {
		return this.getId() == null ? 0 : this.getId().hashCode();
	}
}
